/**
 * @author huangyong
 */
public class SelectionSort {
    public static void sort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            int minIndex = i;
            for (int n = i + 1; n < array.length; n++) {
                if (array[minIndex] > array[n]) {
                    minIndex = n;
                }
            }
            swap(array, minIndex, i);
        }
    }

    private static void swap(int[] array, int minIndex, int index) {
        int temp = array[index];
        array[index] = array[minIndex];
        array[minIndex] = temp;
    }
}
